package com.example.fragment.adapter;


import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.List;
//Fragemtn适配器，基于ViewPager2
public class MyViewPagerAdapter extends FragmentStateAdapter {
   private List<Fragment> fragmentList;

   //构造方法
    public MyViewPagerAdapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
    }
    public  void setFragmentList(List<Fragment> fragmentList){
        this.fragmentList=fragmentList;
    }


    //显示Fragemnt界面
    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragmentList!=null?fragmentList.get(position):null;
    }

    //界面的总数
    @Override
    public int getItemCount() {
        return fragmentList!=null?fragmentList.size():0;
    }
}
